package com.health.tools;

import com.nova.source.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class ResultTextDialog {
    private Dialog mDialog;
    private TextView mTextView;
    private Context context;
    Handler handler=null;
    public ResultTextDialog(Context context) {
        handler = new Handler();
        this.mDialog = new Dialog(context, R.style.dialog);
        LayoutInflater inflater = LayoutInflater.from(context);
        this.context = context;
        View view = inflater.inflate(R.layout.dialog_text, null);
        this.mTextView = ((TextView) view.findViewById(R.id.textview));
        this.mTextView.setTextColor(Color.BLACK);
        this.mDialog.setCancelable(false);
        this.mDialog.setContentView(view);
        this.mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
//				NovaTextDialog.this.mTextView.removeCallbacks(NovaTextDialog.this.cancelRunnable);
                handler.removeCallbacks(ResultTextDialog.this.cancelRunnable);

            }
        });
    }

    public void setText(String text) {
        this.mTextView.setText(text);
    }

    public void setText(int textID) {
        this.mTextView.setText(textID);
    }

    public void cancel() {
        this.mDialog.cancel();
    }

    public void show(String str) {
        if (mDialog != null) {
            this.mTextView.setText(str);
            this.mDialog.show();
        }
    }

    public void show() {
        if (this.mDialog != null) {
            if (!this.mDialog.isShowing()) {
                this.mDialog.show();
            }
        }
    }


    public void showCancleLong() {
        try {
            if (mDialog != null) {
                this.mDialog.show();
                handler.postDelayed(this.cancelRunnable, 3500L);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public void showCancleShort() {
        try {
            if (mDialog != null) {
                this.mDialog.show();
                handler.postDelayed(this.cancelRunnable, 2000L);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private Runnable cancelRunnable = new Runnable() {
        public void run() {
            ResultTextDialog.this.cancel();
        }
    };
}
